home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: more problems with qsort
- Date: Wed, 06 Mar 96 01:04:28 GMT
- Organization: none
- Message-ID: <826074268snz@genesis.demon.co.uk>
- References: <177399702S86.JW1675A@american.edu> <4h0j9e$ng5@clarknet.clark.net> <4h8bud$1vd@castle.nando.net> <825783387snz@genesis.demon.co.uk> <4hd2dd$82q@castle.nando.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4hd2dd$82q@castle.nando.net>
- actuary@nando.net "Bill McCarthy" writes:
-
- >In <825783387snz@genesis.demon.co.uk>, Lawrence Kirby
- > <fred@genesis.demon.co.uk> writes:
- >>In article <4h8bud$1vd@castle.nando.net>
- >> actuary@nando.net "Bill McCarthy" writes:
- >>
- >>>Didn't you mean to type "sizeof( char * )" which, IMHO, could be
- >>>better expressed as "sizeof array[0]" ? Also, there's no need to
- >>>further complicate the call of qsort with the cast on compare if
- >>>you define compare() as:
- >>
- >>The code as written requires a diagnostic from the compiler (if stdlib.h
- >>is included) because the comparison function type takes const void * arguments
- >>and int (*)(void *, void *) is incompatible with
- >>int (*)(const void *, const void *).
- >>
- >>Even if the cast is fixed the code results in undefined behaviour since
- >>an int (char **, char **) function can't be legally called as an
- >>int (const void *, const void *) function which is how qsort() will call it.
- >
- >OK Lawrence, but you are replying to me. I made two points:
- >
- > (1) the "sizeof(char **)" should be replaced with "sizeof(char *)"
- > (2) the cast in front of compare can be eliminated by rewriting compare
- >
- >Which point did you disagree with?
-
- Neither, however it is possible to read "there's no need" as implying that
- there's no harm either. I was just trying to make it clear that it was just
- plain wrong (and potentially harmful).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-